//
//  dgXPYNJLCFInputViewjVJFSJ.m
//  Jlcf_ios
//
//  Created by 邓伟浩 on 2019/4/29.
//  Copyright © 2019 ski. All rights reserved.
//

#import "dgXPYNJLCFInputViewjVJFSJ.h"

@implementation dgXPYNJLCFInputViewjVJFSJ

- (instancetype)initWithInputType:(InputType)inputType {
    _inputType = inputType;
    
    return [self initWithFrame:CGRectZero];
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI {
    
    
    [self addSubview:({
        _ajptsrleftTipsImageViewgYkbmv = [[UIImageView alloc] init];
        _ajptsrleftTipsImageViewgYkbmv.contentMode = UIViewContentModeScaleAspectFit;
        _ajptsrleftTipsImageViewgYkbmv;
    })];
    
    [_ajptsrleftTipsImageViewgYkbmv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.width.height.mas_equalTo(FitRealValue(40));
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    [self addSubview:({
        _jYmrASinputFieldXQCIYG = [[UITextField alloc] init];
        _jYmrASinputFieldXQCIYG.font = FONT(10);
        _jYmrASinputFieldXQCIYG.textColor = [UIColor blackColor];
        _jYmrASinputFieldXQCIYG;
    })];
    [_jYmrASinputFieldXQCIYG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_ajptsrleftTipsImageViewgYkbmv.mas_right).offset(FitRealValue(40));
        make.centerY.mas_equalTo(self.mas_centerY);
        make.height.mas_equalTo(FitRealValue(60));
        make.right.mas_equalTo(self.mas_right);
    }];
    
    UIView *bottomLine = [[UIView alloc] init];
    bottomLine.backgroundColor = LINECOLOR;
    [self addSubview:bottomLine];
    [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_jYmrASinputFieldXQCIYG.mas_left);
        make.right.mas_equalTo(_jYmrASinputFieldXQCIYG.mas_right);
        make.height.mas_equalTo(1);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-FitRealValue(10));
    }];
    
    [self addSubview:({
        _oswKUxrightBtnlkMbAe = [UIButton buttonWithType:UIButtonTypeCustom];
        if (_inputType == InputTypeMessage) {
            [_oswKUxrightBtnlkMbAe setImage:[UIImage imageNamed:@"icon_login_close"] forState:UIControlStateNormal];
        } else if (_inputType == InputTypeCode) {
            [_oswKUxrightBtnlkMbAe setTitle:@"获取验证码" forState:UIControlStateNormal];
            [_oswKUxrightBtnlkMbAe setTitleColor:Theme_Color forState:UIControlStateNormal];
            _oswKUxrightBtnlkMbAe.titleLabel.font = FONT(10);
        }
        
        _oswKUxrightBtnlkMbAe;
    })];
    [_oswKUxrightBtnlkMbAe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right);
        make.height.with.mas_equalTo(FitRealValue(60));
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    [_oswKUxrightBtnlkMbAe addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setInputTextPlaceHolder:(NSString *)placeHolderStr {
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:placeHolderStr attributes:@{NSForegroundColorAttributeName:QTZ_Gray204, NSFontAttributeName:FONT(10)}];
    _jYmrASinputFieldXQCIYG.attributedPlaceholder = attrString;
}

- (void)btnClicked:(UIButton *)button {
    if (_inputType == InputTypeMessage) {
        _jYmrASinputFieldXQCIYG.text = @"";
    }
    if (self.clicked) {
        self.clicked();
    }
}

@end
